package com.cloud.io;

import java.io.*;

/**
 * 字符流
 *
 */
public class CharacterStreamTest {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("src/main/resources/characterStream.txt");
        //字节流转字符流
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        String s1 = "爱你一生一世";
        String s2 = "爱你一生一世";
        bw.write(s1);
        bw.write("\r\n");
        bw.write(s2);

        bw.close();

        FileInputStream fis = new FileInputStream("src/main/resources/characterStream.txt");
        //字节流转字符流并指定编码
        InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String s = null;
        while(null != (s = br.readLine())) {
            System.out.println(s);
        }
        br.close();
    }
}
